#ifndef CARVINGMODULE_H
#define CARVINGMODULE_H

#include <QString>
#include "globalDefine.h"
#include "trajectoryudefine.h"
#include <QMutex>

//const double * joint. 使用mm degree单位
//EmcPose * world. 使用mm degree单位
class EmcControlClass;
class CoordinateManager;
class MotionMessage;

class CarvingModule
{
public:
    CarvingModule(RobotCommonParameter * roboParameterIn,CoordinateManager *coordinateManagerIn
                  , MotionMessage *motionMessageIn);


    int resetAll();
    E_WAVE_STATUS getWaveMotionStatus();
    int setTimeAxisScale(double ratio);
    int startWave();
    int stopWave();
    int ceaseWave();
    int setWaveType(E_WAVE_TYPE typeIn, double waveWidthIn,double wavePeriodIn);
    int setWaveMotionInfo(WeaveMotionCondition infoIn);
    int setWaveAcceleration(double accelerationIn, double maxVelIn, bool isRatio);

    int setNetFeedScale(double scaleIn);
    int setJointVel(int jointNum, double maxVel, double maxAcc);
    int getEmcDebugInfo(EmcDebugInfo &debugOut);
    int getTpQueueSize();
    int loopRealTimeOnce();
    int getJointCommand(std::vector<double> &jointCommandOut);
    int getCoarsePositionCommand(std::vector<double> &coarsePointOut);
    int resetCurrentPosition(std::vector<double> &pointIn,std::vector<double> &jointsIn);
    double getRunningNumber();
    int setRunningNumber_robotArmControl(double numberIn);

    int loadFile();


    int addLine(int idIn, double x, double y, double z, double w, double p ,
                double r, double vel, double acc);
    int addLine(int idIn, std::vector<double> posIn, double vel, double acc);

    int addCircle(int idIn, std::vector<double> posIn, std::vector<double> centerIn,
                  std::vector<double> normalIn, double vel, double acc, int turnsIn);
    int emcTpPause();//没有轨迹的暂停不起作用，添加轨迹后会立刻运行
    int emcTpResume();
    int emcTpClear();
    int emcSetVelLimit(double maxLineVelIn);
    int emcSetRotateLimit(double rotate_eqradiusIn);

    int kinematicsInverse(std::vector<double> posIn, std::vector<double> initialJointIn
                                 , std::vector<double> &jointOut, bool isErrorNotice);

private:
    void test1();


    void* threadRun(void *);
    static void* threadTask( void* classPtr );
    void createThread();

    void* threadRun2(void *);
    static void* threadTask2( void* classPtr );
    void createThread2();

    int parseFile(QString filePath);

private:
    QMutex tpTrajMutex;
    int robotId;
    EmcControlClass *emcControl;
    CoordinateManager* coordinateManager;


};

#endif // CARVINGMODULE_H
